package com.gao.add;

import java.util.concurrent.CountDownLatch;

//计数器
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
//        总数为6
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6 ; i++) {
            new Thread(() -> {

                System.out.println(Thread.currentThread().getName()+"\t 国，被灭");
                //        减一
                countDownLatch.countDown();

            },String.valueOf(i)).start();
        }

//        等待计数器归零，然后再向下执行，如果计数器不归零，就一直等待。
        countDownLatch.await();
        System.out.println("已经没有其他国家了");
//        -1
        countDownLatch.countDown();
        System.out.println("秦国一统天下");






    }
}
